﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainClient
{
    public partial class frmMenuManager : Form
    {
        public frmMenuManager()
        {
            InitializeComponent();
        }

        private void frmMenuManager_Load(object sender, EventArgs e)
        {
            try
            {
                DataAccess.MenuDAO menuDAO = new DataAccess.MenuDAO();
                this.dgv_menu.DataSource = menuDAO.loadMenu().Tables[0].DefaultView;
            }
            catch (Exception e1)
            {
                Console.WriteLine(e1);
                String strError = "加载菜品信息失败！";
                MessageBox.Show(strError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        // 添加新菜
        private void btn_addMenuFood_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = this.dgv_menu.SelectedRows[0];
            string strFoodID = selectedRow.Cells[0].Value.ToString().Trim();
            frmFoodInfo frmD = new frmFoodInfo(strFoodID, frmFoodInfo.OPER_ADDFOOD);
            if (frmD.ShowDialog() == DialogResult.OK)
            {
                this.frmMenuManager_Load(sender, e);
            }
        }

        // 修改菜品
        private void btn_updateMenuFood_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = this.dgv_menu.SelectedRows[0];
            string strFoodID = selectedRow.Cells[0].Value.ToString().Trim();
            frmFoodInfo frmD = new frmFoodInfo(strFoodID, frmFoodInfo.OPER_UPDFOOD);
            if (frmD.ShowDialog() == DialogResult.OK)
            {
                this.frmMenuManager_Load(sender, e);
            }
        }

        // 删除菜品
        private void btn_removeMenuFood_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = this.dgv_menu.SelectedRows[0];
            string strFoodID = selectedRow.Cells[0].Value.ToString().Trim();
            frmFoodInfo frmD = new frmFoodInfo(strFoodID, frmFoodInfo.OPER_RMFOOD);
            if (frmD.ShowDialog() == DialogResult.OK)
            {
                this.frmMenuManager_Load(sender, e);
            }
        }
    } // end of class
}
